package com.yxw.live_vod_boot.controller;

import com.yxw.live_vod_boot.dto.*;
import com.yxw.live_vod_boot.service.ShopService;
import com.yxw.live_vod_boot.vo.LiveBannedUserVO;
import com.yxw.live_vod_boot.vo.ShopExtendVo;
import com.yxw.live_vod_boot.vo.ShopHomePageVO;
import com.yxw.live_vod_boot.vo.UploadSourceMaterialReviewVO;
import com.yxw.live_vod_facade.dto.ShopAddDTO;
import com.yxw.live_vod_facade.dto.ShopExtendAddDTO;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author liuxin
 * @create 2023-11-16 15:23:14
 * @description 店铺管理
 */
@RestController
@Api(value = "店铺管理", tags = "店铺管理")
@Slf4j
@RequestMapping("/api/shop")
public class ShopController {

    @Autowired
    private ShopService shopService;

    @ApiOperation(value = "添加店铺")
    @PostMapping(value = "/add_shop")
    public BaseResult<ShopExtendVo> addShop(@RequestBody @Validated ShopAddDTO dto) {
        ShopExtendVo shopExtendVo = shopService.addShop(dto);
        return BaseResult.doSuccess(shopExtendVo, "添加成功");
    }

    @ApiOperation(value = "添加店铺扩展信息")
    @PostMapping(value = "/add_shop_extend")
    public BaseResult addShopExtend(@RequestBody @Validated ShopExtendAddDTO dto) {
        shopService.addShopExtend(dto);
        return BaseResult.doSuccess(null, "添加成功");
    }

    @ApiOperation(value = "修改店铺状态")
    @PostMapping(value = "/update_shop_status")
    public BaseResult updateShopStatus(@RequestParam("shopId") Long shopId, @RequestParam("status") Integer status) {
        shopService.updateShopStatus(shopId, status);
        return BaseResult.doSuccess(null, "修改成功");
    }

    @ApiOperation(value = "店铺开通点播")
    @PostMapping(value = "/permission_shop")
    public BaseResult permissionShop(@RequestBody @Validated PermissionShopDTO dto) {
        ShopExtendVo vo = shopService.permissionShop(dto);
        return BaseResult.doSuccess(vo, "开通成功");
    }

    @PostMapping(value = "/upload_homepage")
    @ApiOperation(value = "店铺主页信息上传")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form", name = "backgroundFile", value = "背景图文件", required = true, dataType = "__file")
    })
    public BaseResult uploadHomepage(@RequestParam(value = "backgroundFile", required = false) MultipartFile backgroundFile,
                                     @RequestPart UploadHomepageDTO dto) {
        UploadSourceMaterialReviewVO vo = shopService.uploadBackgroundPic(backgroundFile, dto);
        return BaseResult.doSuccess(vo, "上传成功,请等待审核结果");
    }

    @ApiOperation(value = "店铺主页审核处理")
    @PostMapping(value = "/is_shop_homepage_review")
    public BaseResult isShopHomepageReview(@RequestBody @Validated ReviewExamineDTO examineDTO) {
        return shopService.isShopHomepageReview(examineDTO);
    }

    @ApiOperation(value = "获取店铺主页审核列表")
    @PostMapping(value = "/get_shop_homepage_review_list")
    public BaseResult<PageVO<UploadSourceMaterialReviewVO>> getShopHomePageReviewList(@RequestBody ShopHomepageReviewQueryDTO queryDTO) {
        PageVO<UploadSourceMaterialReviewVO> pageVO = shopService.getShopHomePageReviewList(queryDTO);
        return ResultHelper.fillWithSuccess(pageVO);
    }

    @ApiOperation(value = "获取店铺主页审核详情")
    @PostMapping(value = "/get_shop_homepage_review_by_id")
    public BaseResult getShopHomePageReviewByShopId(@RequestParam("materialId") Long materialId) {
        UploadSourceMaterialReviewVO vo = shopService.getShopHomePageReviewById(materialId);
        return BaseResult.doSuccess(vo,"查询成功");
    }

    @ApiOperation(value = "获取店铺主页信息")
    @PostMapping(value = "/get_shop_homepage")
    public BaseResult getShopHomePage(@RequestParam("shopId") Long shopId) {
        ShopHomePageVO vo = shopService.getShopHomepage(shopId);
        return BaseResult.doSuccess(vo, "查询成功");
    }

//    @ApiOperation(value = "点击视频开通权限,同时设置背景图与个性签名")
//    @PostMapping(value = "/enable_video_permissions")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "form",name = "backgroundFile", value = "背景图文件", required = true, dataType = "__file")
//    })
//    public BaseResult enableVideoPermissions(@RequestParam("backgroundFile") MultipartFile backgroundFile,
//                                             @RequestPart UploadHomepageDTO homepageDTO) {
//        shopService.enableVideoPermissions(backgroundFile,homepageDTO);
//        return BaseResult.success();
//    }

    @ApiOperation(value = "修改店铺视频主页信息")
    @PostMapping(value = "/update_shop_homepage")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form",name = "backgroundFile", value = "背景图文件", required = true, dataType = "__file")
    })
    public BaseResult updateShopHomepage(@RequestParam("backgroundFile") MultipartFile backgroundFile,
                                         @RequestPart UploadHomepageDTO homepageDTO) {
        shopService.updateShopHomepage(backgroundFile,homepageDTO);
        return BaseResult.success();
    }

    @ApiOperation(value = "修改店铺信息")
    @PostMapping(value = "/update_shop_information")
    public BaseResult updateShopAvatar(@RequestParam(name = "shopId") Long shopId,
                                       @RequestParam(name = "shopAvatar", required = false) MultipartFile shopAvatar,
                                       @RequestParam(name = "shopName", required = false) String shopName) {
        shopService.updateShopInformation(shopId, shopAvatar, shopName);
        return BaseResult.success();
    }

    @ApiOperation(value = "获取店铺列表(分页)")
    @PostMapping(value = "/get_shop_list")
    public BaseResult getShopList(@RequestBody ShopQueryDTO dto) {
        PageVO<ShopHomePageVO> pageVO = shopService.getShopList(dto);
        return ResultHelper.fillWithSuccess(pageVO);
    }

    @ApiOperation(value = "获取店铺列表")
    @PostMapping(value = "/get_all")
    public BaseResult getAll() {
        List<ShopHomePageVO> list = shopService.getAll();
        return BaseResult.doSuccess(list,"查询成功");
    }

    @ApiOperation(value = "根据店铺查询直播间中被拉黑用户列表")
    @PostMapping(value = "/get_banned_user_list_by_shop")
    public BaseResult getBannedUserListByShop(@RequestParam("shopId") Long shopId) {
        List<LiveBannedUserVO> list = shopService.getBannedUserListByShop(shopId);
        return BaseResult.doSuccess(list,"查询成功");
    }
}
